#!/bin/bash

#!/bin/bash

help() {
  echo "Usage:"
  echo "  zcompose add <service_dir>"
  echo ""
}

core() {
  if [[ $# -eq 0 ]]; then
    help
    exit 0
  fi

  while [[ $# -gt 0 ]]; do
    local key=$1
    local value=$2
    case $key in
    -h | --help)
      help
      shift # past key
      exit 0
      ;;
    *)
      # echo "ERROR: unknown parameter \"$key\""
      # help
      # exit 1
      break
      ;;
    esac
  done

  local service_dir=$1
  if [ "$service_dir" = "" ]; then
    log::error "service dir is requreid"
    exit 1
  fi
  
  log::debug "[$(timestamp)][service] add $service_dir"
  
  if [ ! -d $service_dir ]; then
    log::error "[$(timestamp)][service] service_dir is not a directory"
    exit 1
  fi

  # @TODO PURE
  zmicro config service $service_dir

  log::success "[$(timestamp)][service] add success $service_dir"
}

run() {
  core $@
}

run $@

